package com.itic.hpp.region;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.ResponseCode;
import com.itic.mobile.base.BaseMobile;
import com.itic.system.region.service.HppRegionService;
import com.itic.system.vo.CarrageAreaVo;
import com.itic.system.vo.RegionCityVo;
import com.itic.system.vo.RegionPartVo;
import com.itic.system.vo.RegionProvinceVo;

@Controller
@RequestMapping(value = "/hpp/region")
public class regionInterface extends BaseMobile{
	
	@Autowired 
	private HppRegionService hppRegionService;
	/**
	 * 获取省列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/province")
	@ResponseBody
	public Map<String, Object> province(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			List<RegionProvinceVo> list = hppRegionService.getProvinces();
			resultMap.put(DATA, list);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("regionInterface", "province", e.toString(), "省列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	/**
	 * 获取城市列表
	 * @param provinceId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/city")
	@ResponseBody
	public Map<String, Object> city(String provinceId,HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			List<RegionCityVo> list = hppRegionService.getcityList(provinceId);
			resultMap.put(DATA, list);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("regionInterface", "city", e.toString(), "城市列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	/**
	 * 获取区域列表
	 * @param provinceId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/part")
	@ResponseBody
	public Map<String, Object> part(String cityId,HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			List<RegionPartVo> list = hppRegionService.getpartList(cityId);
			resultMap.put(DATA, list);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("regionInterface", "part", e.toString(), "区域列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
}
